package function

import (
	"strings"
)

type FuncBase interface {
	Build() []interface{}
}

// SelectFunction 为了解析@name这类的数据
func SelectFunction(name string, size int) FuncBase {
	var realName string
	var paramsStr string
	if strings.Contains(name, "(") {
		realName = name[:strings.Index(name, "(")]
		paramsStr = name[strings.Index(name, "(")+1 : strings.Index(name, ")")]
	} else {
		realName = name
	}

	switch realName {
	case "name": // name函数
		return SimpleName(size)
	case "time": // 时间函数
		if paramsStr == "" {
			return DefaultTime("2006-01-02", size)
		} else {
			return DefaultTime(paramsStr, size)
		}
	case "uuid":
		return DefaultUUID(size)
	case "country":
		return DefaultCountry(size, paramsStr)
	case "email":
		return DefaultEmail(size)
	case "ip":
		return DefaultIp(size, paramsStr)
	case "title":
		return DefaultTitle(size)
	case "phone":
		return DefaultPhone(size)
	}
	return nil
}
